package com.fourth.controller.api;

import com.fourth.dao.UBbusinessDao;
import com.fourth.dao.UBorderDao;
import com.fourth.service.UBorderService;
import com.fourth.vo.GnameAndSendVo;
import com.fourth.vo.OrderVo;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Order;
import com.ljx.security.util.WebUtils;
import com.ljx.utils.JwtUtil;
import com.ljx.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2023/3/7 16:01
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/order")
public class UBorderController {

	@Autowired(required = false)
	private UBorderService uBorderService;

	@Autowired(required = false)
	private UBorderDao uBorderDao;

	/**
	 * 查询订单管理信息
	 * @param currentPage
	 * @param pageSize
	 * @param gnameAndSendVo
	 * @return
	 */
	@RequestMapping("/order/selectAll")
	public Result selectAll(@RequestParam(defaultValue = "1") Integer currentPage,@RequestParam(defaultValue = "5") Integer pageSize,@RequestBody GnameAndSendVo gnameAndSendVo){
		System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~");
		System.out.println(gnameAndSendVo);
		return uBorderService.selectOrderAllByBid(currentPage,pageSize, gnameAndSendVo);
	}

	/**
	 * 根据code码改变发货状态
	 * @param code
	 * @return
	 */
	@Autowired(required = false)
	private UBbusinessDao uBbusinessDao;
	@RequestMapping("/order/updateSend")
	public Result updateSend(String code){
		HttpServletRequest request = WebUtils.getRequest();
		String token = request.getHeader("token");
		Map<String, Object> map = JwtUtil.getTokenChaim(token);
		String username = (String) map.get("username");
		BusinessInfo businessInfo = uBbusinessDao.selectBusinessBytelephone(username);
		int i = uBorderDao.updateSend(businessInfo.getId(),code);
		if (i>0){
			return new Result(2000,"发货成功",i);
		}
		return new Result(2000,"发货失败");
	}



}
